package com.airline.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.airline.beans.Employee;
import com.airline.connection.AirlineSystemServiceProxy;
import com.airline.form.DeleteEmployeeIDForm;
import com.airline.form.UpdateEmployeeIDForm;

public class DeleteEmployeeIDAction extends DispatchAction{
	
	AirlineSystemServiceProxy proxy = new AirlineSystemServiceProxy();
	

	public ActionForward deleteId(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		
		String empid = request.getParameter("empid");
		
		
		
		Employee emp = proxy.getEmployee(empid);

		if (null == emp) {

		((DeleteEmployeeIDForm)	(form)).setError("No Employee with the ID " + empid + " exists");
			return mapping.findForward("failure");
		}

		

		boolean res = proxy.deleteEmployee(empid);
		if(res == false){
			((UpdateEmployeeIDForm)	(form)).setError("No Employee with the ID " + empid + " exists");
			return mapping.findForward("failure");
		}
			
		return mapping.findForward("success");
		
	}
		
	
	

}
